<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-input clearable style="width: 240px" v-model="queryParams.search.keywords" placeholder="请输入用户登陆账号查询" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button :loading="loading" type="primary" icon="el-icon-search" size="mini"
          @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['loginlog:list']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <el-table :data="dataList" v-loading="loading" @selection-change="handleSelectionChange" style="width: 100%;">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="userName" width="200" label="用户账号" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="ipaddr" width="200" label="登录IP地址" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="browser" width="200" label="浏览器类型" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="os" width="200" label="操作系统" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="status" width="200" label="登录状态" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status==0" type="success">登陆成功</el-tag>
          <el-tag v-else type="danger">登陆失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="msg" width="200" label="提示消息" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="loginTime" width="200" label="访问时间" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="操作" fixed="right" align="center" width="160" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['loginlog:list']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getDataList" />
    <!-- 弹窗, 新增 / 修改 -->
  </div>
</template>
<script>
  import {
    page,
    deleteById,
    addOrUpdate
  } from "@/api/system/sysloginlog";
  export default {
    data() {
      return {
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        // 总条数
        total: 0,
        //表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 表单参数
        // 显示搜索条件
        showSearch: true,
        form: {},
        // 日期范围
        dateRange: [],
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          search:{}
        },
        dataList: [],
        rules: {},
        addOrUpdateVisible: false
      }
    },
    created() {
      this.getDataList();
      this.initPage();
    },
    methods: {
      initPage() {

      },
      // 获取数据列表
      getDataList() {
        this.loading = true;
        page(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.dataList = response.data.list;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(res => {
          let _this = this
          setTimeout(() => {
            _this.loading = false
          }, 2000)
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getDataList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.addOrUpdateVisible = true;
        this.title = "添加";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init({})
        })
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.addOrUpdateVisible = true;
        this.title = "修改";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(row)
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('确定要删除选中的数据项？').then(function() {
          return deleteById(ids);
        }).then(() => {
          this.getDataList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams = {
          pageNo: 1,
          pageSize: 10,
          search:{

          }
        }
        this.getDataList()
      }
    }
  }
</script>
